using System.Data.SqlClient;
using CoreLibrary.Sql;

namespace Entities.DataBase.Sql {

    internal class UpdateBeforeAppendToFirst : ISqlUpdator<bool> {
        
        private readonly int _left;
        private readonly string _tableName;

        public UpdateBeforeAppendToFirst(int left, string tableName) {
            _left = left;
            _tableName = tableName;
        }

        public string GetSQL() {
            return string.Format(
                @"
                     UPDATE {0} SET RID = RID + 2 WHERE RID > @left;
                     UPDATE {0} SET LID = LID + 2 WHERE LID > @left;
                 
                 ", 
                  _tableName
            );
        }

        public void SetParameters(SqlCommand command) {
            command.Parameters.AddWithValue("@left", _left);
        }

        public bool GetResult(SqlConnection conn, int result) {
            return result >= 0;
        }

    }

}